﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BusinessLogic.ServiceClients;
using BusinessLogic.Security;
using BusinessLogic.Entities;

namespace RusIS.CMS.Controllers
{
    public class LayoutController : Controller
    {
        //
        // GET: /Menu/
        [AllowAnonymous]
        public ActionResult Menu()
        {
            var model = new List<MenuEntity>();
            if (UserPrincipal.Current != null && UserPrincipal.Current.Identity.IsAuthenticated)
            {
                if (UserPrincipal.Current.MenuItems != null && UserPrincipal.Current.MenuItems.Count > 0)
                    model = UserPrincipal.Current.MenuItems;
                //var user = new AuthClient().GetUserSecurityDetails(User.Identity.Name);
                //if (user != null && user.Role != null && user.Role.Menus != null)
                //    model = user.Role.Menus.ToList();
            }
            else
            {
                var role = new AuthClient().GetAnonimusRole();
                if (role != null && role.PermissionMenus != null)
                    model = role.PermissionMenus.Select(p => p.Menu).ToList();
            }
            return PartialView("_Menu", model);
        }

        [AllowAnonymous]
        public ActionResult LoginPartial()
        {
            var model = UserPrincipal.Current;
            return PartialView("_LoginPartial", model);
        }
    }
}
